package com.qf.controller;

import com.qf.pojo.Book;
import com.qf.service.TestBookService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testbook")
public class TestBookController {
    @Autowired
    TestBookService testBookService;

    @RequestMapping("/list")
    public ResultMsg list(String bookName, String bookVersion, String bookType, int page, int limit) {
        return testBookService.findlist(bookName, bookVersion, bookType, page, limit);
    }

    @RequestMapping("/selectone")
    public ResultMsg findone(int bookId) {
        return testBookService.findOne(bookId);
    }

    @RequestMapping("/add")
    public ResultMsg add(Integer bookId,int courseId,int gradeId, String bookName, String bookVersion, String bookType, String bookPublish, String bookPic, String bookContent) {
        return testBookService.insert(null,courseId,gradeId, bookName, bookVersion, bookType, bookPublish, bookPic, bookContent);
    }

    @RequestMapping("/deleteByid")
    public ResultMsg deleteByid(Integer bookId) {
        return testBookService.deleteByid(bookId);
    }

    @RequestMapping("deletelist")
    public ResultMsg deletelist(@RequestBody Map<String,List<Integer>> map) {
        return testBookService.deletelist(map.get("bookIds"));
    }
    @PutMapping("/updateone")
    public ResultMsg update(Integer bookId,Integer courseId,Integer gradeId, String bookName, String bookVersion, String bookType, String bookPublish, String bookPic, String bookContent){
        return testBookService.updateone(bookId,courseId,gradeId, bookName, bookVersion, bookType, bookPublish, bookPic, bookContent);
    }
}